package pers.lan.stack;

/**
 * @author <p><a href="mailto:1728209643@qq.com">XiaoSan</a>
 * @date 2019/9/2 4:55 PM
 */
public class LC_1021 {

    public static void main(String[] args) {
        System.out.println(
                new LC_1021().removeOuterParentheses(
                        "(()())(())((()))"
                )
        );
    }

    public String removeOuterParentheses(String S) {
        int count = 0;
        char[] inputs = S.toCharArray();
        StringBuffer sb = new StringBuffer();
        for (char currentChar : inputs) {
            if (currentChar == '(') {
                if (count > 0) {
                    sb.append(currentChar);
                }
                count++;
            } else {
                count--;
                if (count > 0) {
                    sb.append(currentChar);
                }
            }
        }
        return sb.toString();
    }
}
